package cn.fyl.controller;

import cn.fyl.domain.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/getById/{id}")
    @SentinelResource(value = "user-getById",blockHandler= "userFallbackMethod")
    public User getById(@PathVariable("id") Long id){
        return new User(id,"佘豆传媒","成都一级代理商");
    }

    public User userFallbackMethod(@PathVariable("id") Long id, BlockException e){
        e.printStackTrace();
        return new User(-1L,"限流","遭不住了");
    }
}
